/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exatrez.stripes.action;

import able.stripes.JSP;
import com.google.inject.Inject;
import exatrez.dao.DocumentDAO;
import exatrez.dao.InboxStatusCodeDAO;
import exatrez.dao.ObservationHistoryTaskDAO;
import exatrez.dao.SeverityCodeDAO;
import exatrez.dao.StatusRemarkCodeDAO;
import exatrez.dao.VesselDAO;
import exatrez.manager.EmailManager;
import exatrez.manager.InboxManager;
import exatrez.manager.ObservationManager;
import exatrez.manager.ShipVisit3IntegrationManager;
import exatrez.model.Document;
import exatrez.model.Folder;
import exatrez.model.Groups;
import exatrez.model.Inbox;
import exatrez.model.InfoAudit;
import exatrez.model.Observation;
import exatrez.model.ObservationHistoryTask;
import exatrez.model.ObservationSummary;
import exatrez.model.ObservationTask;
import exatrez.model.SeverityCode;
import exatrez.model.StatusRemarkCode;
import exatrez.model.User;
import exatrez.model.UserGroup;
import exatrez.model.Vessel;
import exatrez.stripes.BaseActionBean;
import exatrez.stripes.config.AuthRequired;
import exatrez.stripes.util.EmailUtil;
import exatrez.stripes.util.FileUtil;
import freemarker.cache.FileTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.Template;
import java.io.File;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ErrorResolution;
import net.sourceforge.stripes.action.FileBean;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.StreamingResolution;
import net.sourceforge.stripes.action.UrlBinding;
import net.sourceforge.stripes.security.action.Secure;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author fikri
 */
@UrlBinding("/observation")
@AuthRequired
public class ObservationAction extends BaseActionBean {

    private static Logger LOG = LoggerFactory.getLogger(ObservationAction.class);
    private Observation observation;
    private ObservationTask observationTask;
    private ObservationHistoryTask history;
    private List<Observation> listOfObservation;
    private List<Observation> listOfDraftObservation;
    private String[] summary = new String[2];
    private String[] summaryId = new String[2];
    @Inject
    private ObservationManager manager;
    @Inject
    private SeverityCodeDAO severityCodeDAO;
    @Inject
    private InboxStatusCodeDAO inboxStatusDAO;
    @Inject
    private StatusRemarkCodeDAO statusRemarkCodeDAO;
    @Inject
    private DocumentDAO documentDAO;
    @Inject
    private VesselDAO vesselDAO;
    @Inject
    exatrez.stripes.Configuration conf;
    @Inject
    private EmailManager emailManager;
    @Inject
    private InboxManager inboxManager;
    @Inject
    private EmailUtil emailUtil;
    @Inject
    private ObservationHistoryTaskDAO historyDAO;            
    @Inject
    private ShipVisit3IntegrationManager svManager;
    private List<FileBean> documents;
    private FileBean document;
    private String tabPosition = "0";
    private String id;
    private static int CLOSED = 1;
    private static int OPEN = 2;
    private static int PENDING = 3;
    
    private static int LOW = 1;
    private static int MEDIUM = 2;
    private static int HIGH = 3;
    private int totals = 0;
    private int totalsDay = 0;
    private String[] cb;    
    
    private String yearOfInspection;
    
    private String obsID;
    
    private String forXlsx = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    private String forDocx = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
    private String forPptx = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
    private String forXls = "application/vnd.ms-excel";
    private String forDoc = "application/msword";
    private String forPpt = "application/vnd.ms-powerpoint";
    private String forPdf = "application/pdf";
    
    private String forVideoMov = "video/quicktime";
    private String forVideoMkv = "video/x-matroska";
    private String forVideoMp4 = "video/mp4";
    private String forVideoAvi = "video/x-msvideo";
    private String forVideoMpeg= "video/mpeg";
    private String forVideoWmv = "application/octet-stream";
    private String forVideoAsf = "video/x-ms-asf";
    private String forVideoFlv = "video/x-flv";
    private String forVideoRmvb= "application/vnd.rn-realmedia-vbr";
    private String forVideo3gp = "video/3gpp";
    
    private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    
    static String intToString(int num, int digits) {
        assert digits > 0 : "Invalid number of digits";

        // create variable length array of zeros
        char[] zeros = new char[digits];
        Arrays.fill(zeros, '0');
        // format number as String
        DecimalFormat df = new DecimalFormat(String.valueOf(zeros));

        return df.format(num);
    }

    @DefaultHandler
    public Resolution newReportForm() {
        String detail = getContext().getRequest().getParameter("detail");
        getContext().getRequest().setAttribute("detail", detail);
        return new JSP("observation/new_report.jsp");
    }

//    @Secure(roles = "1,4,9")
    public Resolution listReportForm() {
        return new JSP("observation/list_report.jsp");
    }

    @Secure(roles = "1")
    public Resolution draftReportForm() {
        return new JSP("observation/draft_report.jsp");
    }
    
    public Resolution closeReportForm() {
        return new JSP("observation/close_report.jsp");
    }

    public Resolution superintendenceReportForm() {
        return new JSP("observation/superintendence_list.jsp");
    }

    public Resolution searchListReport() {
        User user = getContext().getCurrentUser();
        listOfObservation = manager.getListReport(observation, user);
        return new JSP("observation/list_report.jsp");
    }
    
    public Resolution searchCloseReport() {
        User user = getContext().getCurrentUser();
        listOfObservation = manager.getCloseReport(observation, user, yearOfInspection);
        return new JSP("observation/close_report.jsp");
    }
    
    public Resolution viewCloseReport() {
        id = getContext().getRequest().getParameter("id");
        if (StringUtils.isNotBlank(id)) {
            observation = manager.getObservation(id);
            if (observation != null) {
                getContext().getRequest().setAttribute("detail", true);
                List<ObservationSummary> listOfSummary = observation.getSummaryList();
                if (listOfSummary != null && listOfSummary.size() > 0) {
                    for (int i = 0; i < listOfSummary.size(); i++) {
                        ObservationSummary sum = listOfSummary.get(i);
                        summary[i] = sum.getSummary();
                    }
                }
            }
        }
        return new JSP("observation/observation_view_only.jsp");
    }

    public Resolution searchDraftReport() {
        User user = getContext().getCurrentUser();
        listOfDraftObservation = manager.getDraftList(observation, user);
        return new JSP("observation/draft_report.jsp");
    }

    public Resolution searchSuperintendenceReport() {
        User user = getContext().getCurrentUser();
        listOfObservation = manager.getSuperintendenceListReport(observation, user);
        return new JSP("observation/superintendence_list.jsp");
    }

    public Resolution acquire() {
        id = getContext().getRequest().getParameter("id");
        User user = getContext().getCurrentUser();
        if (StringUtils.isNotBlank(id)) {
            observation = manager.getObservation(id);
            if (observation != null) {
                observation.setAcquired("Y");
//                observation.setAcquiredBy(user);
                manager.saveOrUpdate(observation);
                List<ObservationSummary> listOfSummary = observation.getSummaryList();
                if (listOfSummary != null && listOfSummary.size() > 0) {
                    for (int i = 0; i < listOfSummary.size(); i++) {
                        ObservationSummary sum = listOfSummary.get(i);
                        summary[i] = sum.getSummary();
                    }
                }
            }
        }
        return new JSP("observation/superintendence_form.jsp");
    }

    public Resolution view() {

        id = getContext().getRequest().getParameter("id");
        tabPosition = getContext().getRequest().getParameter("tabPosition");
        String error =  getContext().getRequest().getParameter("error");
        if (StringUtils.isNotBlank(id)) {
            observation = manager.getObservation(id);
            if (observation != null) {
                getContext().getRequest().setAttribute("detail", true);
                List<ObservationSummary> listOfSummary = observation.getSummaryList();
                if (listOfSummary != null && listOfSummary.size() > 0) {
                    for (int i = 0; i < listOfSummary.size(); i++) {
                        ObservationSummary sum = listOfSummary.get(i);
                        LOG.debug("<view> summary"+i+" :"+sum.getSummary());
                        summary[i] = sum.getSummary();
                        summaryId[i] = String.valueOf(sum.getObservationSummaryId());
                    }
                }
            }
        }
        if (StringUtils.isNotBlank(error)) {
            addSimpleError(error);
        }
        return new JSP("observation/new_report.jsp");
    }

    public Resolution viewReadOnly() {

        id = getContext().getRequest().getParameter("id");
        tabPosition = getContext().getRequest().getParameter("tabPosition");
        if (StringUtils.isNotBlank(id)) {
            observation = manager.getObservation(id);
            if (observation != null) {
                getContext().getRequest().setAttribute("detail", true);
                List<ObservationSummary> listOfSummary = observation.getSummaryList();
                if (listOfSummary != null && listOfSummary.size() > 0) {
                    for (int i = 0; i < listOfSummary.size(); i++) {
                        ObservationSummary sum = listOfSummary.get(i);
                        summary[i] = sum.getSummary();
                    }
                }
            }
        }
        return new JSP("observation/view_only_report.jsp");
    }

    public Resolution updateObsRemarkStatus() {

        User user = getContext().getCurrentUser();
        id = getContext().getRequest().getParameter("id");
        tabPosition = getContext().getRequest().getParameter("tabPosition");
        if (StringUtils.isNotBlank(id)) {
            observation = manager.getObservation(id);
            if (observation != null) {
                getContext().getRequest().setAttribute("detail", true);
                List<ObservationSummary> listOfSummary = observation.getSummaryList();
                if (listOfSummary != null && listOfSummary.size() > 0) {
                    for (int i = 0; i < listOfSummary.size(); i++) {
                        ObservationSummary sum = listOfSummary.get(i);
                        summary[i] = sum.getSummary();
                    }
                }
            }
        }
        
        List<UserGroup> list = user.getRoles();
        if (!list.isEmpty()) {
            for (UserGroup userGroups : list) {
                Groups grp = userGroups.getGroup();
                if (grp != null){
                    if (grp.getGroupId() == 4 || grp.getGroupId() == 9 || grp.getGroupId() == 18 || grp.getGroupId() == 24) { // view only for coo || topM || depH || sat
                        return new JSP("observation/observation_view_only.jsp");
                    }
                }
            }
        }
        
        return new JSP("observation/ma_update_form.jsp");
    }

    public Resolution saveGeneral() {

        InfoAudit ia = observation.getInfoAudit();
        User user = getContext().getCurrentUser();
        if (ia == null) {
            ia = new InfoAudit();
            ia.setCreateDate(new Date());
            ia.setCreateId(user);
            ia.setUpdateDate(new Date());
            ia.setUpdateId(user);
        } else {
            ia.setUpdateDate(new Date());
            ia.setUpdateId(user);
        }
        observation.setInfoAudit(ia);
        observation.setStatus(statusRemarkCodeDAO.findById(OPEN));
        observation = manager.saveOrUpdate(observation);
        getContext().getRequest().setAttribute("detail", true);
        addSimpleMessage("Success");
        LOG.debug("finish");

        return new RedirectResolution(ObservationAction.class, "view")
                .addParameter("id", observation.getObservationId());

//         return new JSP("observation/new_report.jsp");
    }

    public Resolution saveSummary() {

        List<ObservationSummary> listOfSummary = new ArrayList<ObservationSummary>();

        observation = manager.getObservation(String.valueOf(observation.getObservationId()));

        InfoAudit ia = observation.getInfoAudit();
        User user = getContext().getCurrentUser();
        if (ia == null) {
            ia = new InfoAudit();
            ia.setCreateDate(new Date());
            ia.setCreateId(user);
            ia.setUpdateDate(new Date());
            ia.setUpdateId(user);
        } else {
            ia.setUpdateDate(new Date());
            ia.setUpdateId(user);
        }
        observation.setInfoAudit(ia);
        observation = manager.saveOrUpdate(observation);
        
        for (int i=0; i<2; i++) {
            ObservationSummary sum = new ObservationSummary();
            if (StringUtils.isNotBlank(summaryId[i])) {
                sum = manager.findSummary(Integer.parseInt(summaryId[i]));
                if (sum != null) {                    
//                    sum.setSummary(StringEscapeUtils.escapeXml(summary[i]));
//                    LOG.debug("<saveSummary> Request.characterEncoding : "+getContext().getRequest().getCharacterEncoding());
//                    LOG.debug("<saveSummary> Response.characterEncoding : "+getContext().getResponse().getCharacterEncoding());
//                    LOG.debug("<saveSummary> summary ["+i+"] : "+summary[i]);
//                    try {
//                        LOG.debug("<saveSummary> convert1 ::"+ new String(summary[i].getBytes("Windows-1252"),"ISO-8859-1"));
//                        LOG.debug("<saveSummary> convert2 ::"+ new String(summary[i].getBytes(),"ISO-8859-2"));
//                        LOG.debug("<saveSummary> convert3 ::"+ new String(summary[i].getBytes(),"ISO-8859-3"));
//                        LOG.debug("<saveSummary> convert4 ::"+ new String(summary[i].getBytes(),"ISO-8859-4"));
//                        LOG.debug("<saveSummary> convert5 ::"+ new String(summary[i].getBytes(),"ISO-8859-5"));
//                        LOG.debug("<saveSummary> convert6 ::"+ new String(summary[i].getBytes(),"ASCII"));
//                        LOG.debug("<saveSummary> convert7 ::"+ new String(summary[i].getBytes(),"Windows-1252"));
//                    } catch (UnsupportedEncodingException ex) {
//                        ex.printStackTrace();
//                    }
                    sum.setSummary(summary[i]);
                    InfoAudit au = sum.getInfoAudit();
                    if (au != null) {
                        au.setUpdateDate(new Date());
                        au.setUpdateId(user);
                    } else {
                        au = new InfoAudit();
                        au.setCreateDate(new Date());
                        au.setCreateId(user);
                        au.setUpdateDate(new Date());
                        au.setUpdateId(user);
                    }
                    sum.setInfoAudit(au);
                    listOfSummary.add(sum);
                } 
            } else if (StringUtils.isNotBlank(summary[i])){                
                sum.setObservation(observation);
//                sum.setSummary(StringEscapeUtils.escapeXml(summary[i]));
                sum.setSummary(summary[i]);
                InfoAudit audit = new InfoAudit();
                audit.setCreateDate(new Date());
                audit.setCreateId(user);
                audit.setUpdateDate(new Date());
                sum.setInfoAudit(audit);
                listOfSummary.add(sum);
            }
        }

//        List<ObservationSummary> summaries = observation.getSummaryList();
//        if (summaries != null && !summaries.isEmpty()) {
//            for (int i = 0; i < summaries.size(); i++) {
//                ObservationSummary sum = summaries.get(i);
//                sum.setSummary(summary[i]);
//                InfoAudit audit = sum.getInfoAudit();
//                if (audit != null) {
//                    audit.setUpdateId(user);
//                    audit.setUpdateDate(new Date());
//                } else {
//                    audit = new InfoAudit();
//                    audit.setCreateDate(new Date());
//                    audit.setCreateId(user);
//                    audit.setUpdateDate(new Date());
//                }
//                sum.setInfoAudit(audit);
//                listOfSummary.add(sum);
//            }
//        } else {
//            for (int i = 0; i < 2; i++) {
//                if (StringUtils.isBlank(summary[i])) continue;
//                ObservationSummary sum = new ObservationSummary();
//                sum.setObservation(observation);
//                sum.setSummary(summary[i]);
//                InfoAudit audit = new InfoAudit();
//                audit.setCreateDate(new Date());
//                audit.setCreateId(user);
//                audit.setUpdateDate(new Date());
//                sum.setInfoAudit(audit);
//                listOfSummary.add(sum);
//            }
//        }
        listOfSummary = manager.saveOrUpdateSummary(listOfSummary);
        for (int i = 0; i< listOfSummary.size(); i++) {
            summaryId[i]= String.valueOf(listOfSummary.get(i).getObservationSummaryId());
        }
        tabPosition = "0";
        getContext().getRequest().setAttribute("detail", true);
        return new JSP("observation/new_report.jsp");
    }

    public Resolution addEditTaskForm() {
        String ids = getContext().getRequest().getParameter("ids");
        id = getContext().getRequest().getParameter("id");
        if (StringUtils.isNotBlank(id)) {
            observation = manager.getObservation(id);
        }
        if (StringUtils.isNotBlank(ids)) {
            observationTask = manager.getObservationTask(ids);
        } 
        
       if (observation != null) {
                Vessel vessel = observation.getVessel();
                obsID = manager.getSequenceID(vessel.getVesselAbbr());                
            }        
        
        return new JSP("observation/new_obs.jsp").addParameter("popup", true);
    }

    public Resolution saveTask() {
        
        User user = getContext().getCurrentUser();
        InfoAudit ia = new InfoAudit();
        ia.setCreateId(user);
        ia.setCreateDate(new Date());
        
        boolean isNewObs = false;

        observation = manager.getObservation(String.valueOf(observation.getObservationId()));
        Vessel vessel = observation.getVessel();
        StatusRemarkCode remark = statusRemarkCodeDAO.findById(OPEN);
        
        ObservationTask task = new ObservationTask();
        if (observationTask.getObservationTaskId() != null 
                && !observationTask.getObservationTaskId().equals("0")) {
            task = manager.getObservationTask(observationTask.getObservationTaskId());
            obsID = manager.getSequenceID(vessel.getVesselAbbr());
            obsID = obsID + intToString(Integer.parseInt(observationTask.getSeq()),3);
            if (task == null) {    
                task = new ObservationTask();
                task.setObservationTaskId(obsID);
            }
        } else {
            obsID = manager.getSequenceID(vessel.getVesselAbbr());
            obsID = obsID + intToString(Integer.parseInt(observationTask.getSeq()),3);
            ObservationTask task2 = manager.getObservationTask(obsID);
            if (task2 != null) {
                StringBuilder sb = new StringBuilder("OBS ID ")
                        .append(obsID)
                        .append(" already EXIST!!");
                return new RedirectResolution(ObservationAction.class, "view")
                .addParameter("error", sb.toString())
                .addParameter("id", observation.getObservationId())
                .addParameter("tabPosition", 1);
            }
            task.setObservationTaskId(obsID);
            isNewObs = true;
//            task.setObservationTaskId(manager.getSequence(vessel.getVesselAbbr()));
        }

        int severityCodeId = observationTask.getSeverity().getSeverityCodeId();
        SeverityCode severityCode = severityCodeDAO.findById(severityCodeId);        
        task.setInfo(observationTask.getInfo());
        task.setTitle(observationTask.getTitle());
        task.setDetail(observationTask.getDetail());
        task.setSeverity(severityCode);
        task.setStatusRemarks(remark);
        task.setObservation(observation);
        task.setSeq(observationTask.getSeq());
        if ( observationTask.getSeverityDayCount() != null )
            task.setSeverityDayCount(observationTask.getSeverityDayCount());
        else {
            if (severityCode != null) {
                task.setSeverityDayCount(severityCode.getSeverityDay());
            }
        }
        task.setInfoAudit(ia);
        
        manager.saveOrUpdateTask(task);
        
        if (!isNewObs 
                && !obsID.equals(task.getObservationTaskId())) {
            manager.updateTasks(task.getObservationTaskId(), obsID);
        }

        doSaveUpdateModifyTask();

        return new RedirectResolution(ObservationAction.class, "view")
                .addParameter("id", observation.getObservationId())
                .addParameter("tabPosition", 1);
    }

    public Resolution viewDocuments() {
        String ids = getContext().getRequest().getParameter("id");
        String actionPlan = getContext().getRequest().getParameter("action_plan");
        if (StringUtils.isNotBlank(ids)) {
            observationTask = manager.getObservationTask(ids);
        }
        getContext().getRequest().setAttribute("action_plan", actionPlan);
        return new JSP("observation/edit_documents.jsp").addParameter("popup", true);
    }

    public Resolution saveDocuments() {
        //TODO : begin.transaction

        String documentPath = conf.getProperty("document.path");
        InfoAudit ia = new InfoAudit();


        List<Document> obsDocument = new ArrayList<Document>();

        ObservationTask task = manager.getObservationTask(String.valueOf(observationTask.getObservationTaskId()));
        Folder folder = task.getFolder();
        if (folder == null) {
            folder = new Folder();
            manager.saveOrUpdateFolder(folder);
            task.setFolder(folder);
            manager.saveOrUpdateTask(task);
        }

        String path = documentPath + (documentPath.endsWith(File.separator) ? "" : File.separator) + folder.getFolderId() + File.separator;
        String docPath = File.separator + folder.getFolderId() + File.separator;

        if (document != null) {
            FileUtil fileUtil = new FileUtil(path);
            try {
//                    path = path + document.getFileName();
                fileUtil.saveFile(document.getFileName(), document.getInputStream(), document.getSize());
                Document doc = new Document();
                doc.setTitle(document.getFileName());
                doc.setDocumentPath(docPath + document.getFileName());
                doc.setFolder(folder);
                doc.setContentType(document.getContentType());
                ia.setCreateDate(new Date());
                ia.setCreateId(getContext().getCurrentUser());
                doc.setInfoAudit(ia);
                manager.saveOrUpdateDocument(doc);
            } catch (Exception ex) {
                LOG.error("error while saving file {}", ex.getCause().getMessage());
            }
        }

//        observationTask = manager.getObservationTask(String.valueOf(task.getObservationTaskId()));        

//        if (!documents.isEmpty()) {
//            FileUtil fileUtil = new FileUtil(path);
//            for (FileBean fbean : documents) {  
//                try {                    
//                    path = path + fbean.getFileName();
//                    fileUtil.saveFile(fbean.getFileName(), fbean.getInputStream());
//                    ObservationDocument doc = new ObservationDocument();
//                    doc.setDocumentPath(docPath + fbean.getFileName());
//                    doc.setFolder(folder);
//                    obsDocument.add(doc);
//                }catch (Exception ex) {
//                    LOG.error("error while saving file {}", ex.getCause().getMessage());
//                }
//            }
//        }
//        if(!obsDocument.isEmpty()){
//            manager.saveOrUpdateDocument(obsDocument);
//        }

        return new RedirectResolution(ObservationAction.class, "viewDocuments")
                .addParameter("id", observationTask.getObservationTaskId());

//        return new JSP("observation/edit_documents.jsp").addParameter("popup", true);
    }

    public Resolution viewDocumentsActionPlan() {
        String ids = getContext().getRequest().getParameter("id");
        String actionPlan = getContext().getRequest().getParameter("action_plan");
        if (StringUtils.isNotBlank(ids)) {
            observationTask = manager.getObservationTask(ids);
        }
        getContext().getRequest().setAttribute("action_plan", actionPlan);
        return new JSP("observation/edit_documents_action_plan.jsp").addParameter("popup", true);
    }

    public Resolution saveDocumentsActionPlan() {
        //TODO : begin.transaction

        String documentPath = conf.getProperty("document.path");
        if (StringUtils.isBlank(documentPath)) {
            return new ErrorResolution(500,
                    "configuration of \"document.path\" not found!");
        }
        InfoAudit ia = new InfoAudit();


        List<Document> obsDocument = new ArrayList<Document>();

        ObservationTask task = manager.getObservationTask(String.valueOf(observationTask.getObservationTaskId()));
        Folder folder = task.getActionPlasFolderTemp();
        if (folder == null) {
            folder = new Folder();
            manager.saveOrUpdateFolder(folder);
            task.setActionPlasFolderTemp(folder);
            manager.saveOrUpdateTask(task);
        }

        String path = documentPath + (documentPath.endsWith(File.separator) ? "" : File.separator) + folder.getFolderId() + File.separator;
        String docPath = File.separator + folder.getFolderId() + File.separator;

        if (document != null) {
            FileUtil fileUtil = new FileUtil(path);
            try {
//                    path = path + document.getFileName();
                fileUtil.saveFile(document.getFileName(), document.getInputStream(), document.getSize());
                Document doc = new Document();
                doc.setTitle(document.getFileName());
                doc.setDocumentPath(docPath + document.getFileName());
                doc.setFolder(folder);
                doc.setContentType(document.getContentType());
                ia.setCreateDate(new Date());
                ia.setCreateId(getContext().getCurrentUser());
                doc.setInfoAudit(ia);
                manager.saveOrUpdateDocument(doc);
            } catch (Exception ex) {
                LOG.error("error while saving file {}", ex.getCause().getMessage());
            }
        }

        observationTask = manager.getObservationTask(String.valueOf(observationTask.getObservationTaskId()));

//        return new JSP("observation/edit_documents_action_plan.jsp").addParameter("popup", true);
        return new RedirectResolution(ObservationAction.class, "viewDocumentsActionPlan")
                .addParameter("id", observationTask.getObservationTaskId());
    }

    public Resolution deleteDocument() {
        id = getContext().getRequest().getParameter("id");
        String ids = getContext().getRequest().getParameter("ids");
        Document d = documentDAO.findById(Integer.valueOf(id));
        String actionPlan = getContext().getRequest().getParameter("action_plan");

        manager.deleteDocument(d);

        if (StringUtils.isNotBlank(ids)) {
            observationTask = manager.getObservationTask(ids);
        }

        if (StringUtils.isNotBlank(actionPlan)) {
            return new JSP("observation/edit_documents_action_plan.jsp").addParameter("popup", true);
        } else {
            return new JSP("observation/edit_documents.jsp").addParameter("popup", true);
        }
    }

    public Resolution viewDocsActionPlan() {
        String ids = getContext().getRequest().getParameter("ids");
        if (StringUtils.isNotBlank(ids)) {
            observationTask = manager.getObservationTask(ids);
        }
        return new JSP("observation/view_documents_action_plan.jsp").addParameter("popup", true);
    }
    
    public Resolution viewHistoryFolderDoc() {
        String idHistory = getContext().getRequest().getParameter("ids");
        if (StringUtils.isNotBlank(idHistory)) {
            history = historyDAO.findById(Integer.parseInt(idHistory));
        }        
        return new JSP("observation/view_history_documents.jsp").addParameter("popup", true);        
    }

    public Resolution viewDocs() {
        String ids = getContext().getRequest().getParameter("ids");
        if (StringUtils.isNotBlank(ids)) {
            observationTask = manager.getObservationTask(ids);
        }
        return new JSP("observation/view_documents.jsp").addParameter("popup", true);
    }

    public Resolution taskDetailPopup() {
        String ids = getContext().getRequest().getParameter("ids");
        if (StringUtils.isNotBlank(ids)) {
            observationTask = manager.getObservationTask(ids);
        }
        return new JSP("observation/task_detail_popup.jsp").addParameter("popup", true);
    }

    public Resolution sendToSuper() {

        User user = getContext().getCurrentUser();
        User toUser = null;

        if (cb.length > 0) {
            List<ObservationTask> list = new ArrayList<ObservationTask>();
            List<ObservationHistoryTask> histories = new ArrayList<ObservationHistoryTask>();
            for (String observationTaskId : cb) {
                ObservationTask task = manager.getObservationTask(observationTaskId);
                if (task != null) {
                    task.setStatusSubmitMa("1");
                    task.setStatusSubmitSuper("0");
//                    task.setMaRemarks(StringEscapeUtils.escapeXml(task.getMaRemarksTemp()));
                    task.setMaRemarks(task.getMaRemarksTemp());
                    task.setStatusRemarks(task.getStatusRemarksTemp());
//                    task.setActionPlasFolderTemp(task.getActionPlasFolder());
                    task.setActionPlasFolderTemp(null);
                    list.add(task);

                    ObservationHistoryTask history = manager.getLatestHistory(observationTaskId);
                    if (history != null) {
//                        StringBuilder sb = new StringBuilder(StringEscapeUtils.escapeXml(task.getMaRemarksTemp()));
                        StringBuilder sb = new StringBuilder(task.getMaRemarksTemp());
                        if (sb.length() > 0) {
                            sb.append("-by ").append(user.getUserId());
                        }
                        history.setRemarks(sb.toString());
                        history.setResponseDate(new Date());
                        history.setStatusRemarks(task.getStatusRemarksTemp());
                        histories.add(history);
                    }
                }
            }

            observation = manager.getObservation(String.valueOf(observation.getObservationId()));
            if (!list.isEmpty()) {
                manager.saveOrUpdateTaskWithHistory(list, histories);
                doSaveUpdateModifyTask();
                List<Map<String,String>> listOfTasks = manager.getTasks(user.getUserId());
                if (listOfTasks != null && !listOfTasks.isEmpty()) {                    
                    toUser = observation.getAssignee();
                    User toCrew = observation.getVessel().getCrewExe();
                    User toProc = observation.getVessel().getProcExe();
                    String content = getTemplate(listOfTasks, toUser.getUserId(), user.getUserId());
                    InfoAudit ia = new InfoAudit();
                    Inbox inbox = new Inbox();
                    inbox.setStatus(inboxStatusDAO.findById(1));
                    inbox.setSenderEmail(user.getEmail());                
                    inbox.setReceiverEmail(toUser.getEmail()+","+toCrew.getEmail()+","+toProc.getEmail());               
                    ia.setCreateId(user);
                    ia.setCreateDate(new Date());
                    inbox.setInfoAudit(ia);                
                    inbox.setTitle("OBSERVATION ACKNOWLEDGEMENT");
                    inbox.setContent(content);
                    inboxManager.saveOrUpdate(inbox);
                }                
            }
            
            boolean close = true;            
            if (observation != null) {
                List<ObservationTask> tasks = observation.getTaskList();
                for (ObservationTask t : tasks) {
                    if (t.getStatusRemarks() == null) {
                        close = false;
                        break;
                    } else if (
                            t.getStatusRemarks().getStatusRemarkCodeId() == OPEN ||
                            t.getStatusRemarks().getStatusRemarkCodeId() == PENDING) {
                        close = false;
                        break;
                    }
                }
                if (close) {                    
                    InfoAudit ia = observation.getInfoAudit();
                    ia.setUpdateDate(new Date());
                    ia.setUpdateId(user);
                    observation.setStatus(statusRemarkCodeDAO.findById(CLOSED));
                    observation.setInfoAudit(ia);
                    manager.saveOrUpdate(observation);
                }
            }
            
        }
        setTabPosition("2");
        return new JSP("observation/ma_update_form.jsp");
    }

    public Resolution sendToMa() {

        User user = getContext().getCurrentUser();        

        if (cb.length > 0) {
            List<String> toUser = new ArrayList<String>();
            List<String> toUserName = new ArrayList<String>();
            List<ObservationTask> list = new ArrayList<ObservationTask>();
            List<ObservationHistoryTask> histories = new ArrayList<ObservationHistoryTask>();
            for (String observationTaskId : cb) {
                ObservationTask task = manager.getObservationTask(observationTaskId);
                if (task != null) {
                    task.setStatusSubmitSuper("1");
                    task.setStatusSubmitMa("0");
                    task.setSummary(task.getSummaryTemp());
                    task.setActionPlasFolder(task.getActionPlasFolderTemp());
                    task.setActionPlasFolderTemp(null);
                    list.add(task);

                    ObservationHistoryTask history = new ObservationHistoryTask();
                    history.setObservationTask(task);
//                    StringBuilder sb = new StringBuilder(StringEscapeUtils.escapeXml(task.getSummaryTemp()));
                    StringBuilder sb = new StringBuilder(task.getSummaryTemp());
                    if (sb.length() > 0) {
                        sb.append("-by ").append(user.getUserId());
                    }
//                    Folder folder = new Folder();
                    history.setFolder(task.getActionPlasFolder());
                    history.setActionPlanSummary(sb.toString());
                    history.setResponseDate(new Date());
                    history.setStatusRemarks(task.getStatusRemarksTemp());
                    histories.add(history);
                    InfoAudit ia = task.getInfoAudit();
                    if (ia != null && ia.getCreateId() != null) {
                        if (toUser.contains(ia.getCreateId().getEmail())) continue;
                        toUser.add(ia.getCreateId().getEmail());
                        toUserName.add(ia.getCreateId().getUserId());
                        
                    }
                }
            }           
            

            observation = manager.getObservation(String.valueOf(observation.getObservationId()));
            if (!list.isEmpty()) {
                manager.saveOrUpdateTaskWithHistory(list,histories);                
                doSaveUpdateModifyTask();
                
                List<Map<String,String>> lisfOfTasks = manager.getTasks(user.getUserId());
                
                if (lisfOfTasks != null && !lisfOfTasks.isEmpty()) {   
                    InfoAudit ia = new InfoAudit();
                    ia.setCreateId(user);
                    ia.setCreateDate(new Date());
                    Inbox inbox = new Inbox();
                    inbox.setInfoAudit(ia);
                    inbox.setStatus(inboxStatusDAO.findById(1));
                    inbox.setSenderEmail(user.getEmail());

                    if (!toUser.isEmpty()) {
                        StringBuilder sb = new StringBuilder();
                        for (String str : toUser) {
                            if (sb.length() > 0) {
                                sb.append(",");
                            }
                            sb.append(str);
                        }
                        inbox.setReceiverEmail(sb.toString());
                    }
                    StringBuilder sb = new StringBuilder();
                    if(!toUserName.isEmpty()) {
                        for (String str : toUserName) {
                            if (sb.length() > 0) {
                                sb.append(",");
                            }
                            sb.append(str);
                        }
                    }
                    String content = getTemplate(lisfOfTasks, sb.toString(), user.getUserId());
                    inbox.setContent(content);
                    inbox.setTitle("OBSERVATION ACKNOWLEDGEMENT");
                    inboxManager.saveOrUpdate(inbox);
                }
            }
        }

        setTabPosition("2");
        return new JSP("observation/superintendence_form.jsp");
    }

    public Resolution deleteTask() {
        id = getContext().getRequest().getParameter("id");
        observationTask = manager.getObservationTask(id);
        id = String.valueOf(observationTask.getObservation().getObservationId());
        manager.deleteTask(observationTask);
        return new RedirectResolution(ObservationAction.class, "view")
                .addParameter("id", id)
                .addParameter("tabPosition", 1);
    }

    public Resolution submit() {

        String ids = getContext().getRequest().getParameter("id");
        Observation obs = manager.getObservation(ids);
        User superintedence = obs.getVessel().getSuperintendence();
        if (superintedence == null) {
            StringBuilder sb = new StringBuilder("Vessel ")
                    .append(obs.getVessel().getVesselName())
                    .append(" has no superintedence.");
            addSimpleError(sb.toString());
            return new JSP("observation/draft_report.jsp");
        }
        List<ObservationTask> tasks = obs.getTaskList();
        List<ObservationTask> tasksToSave = new ArrayList<ObservationTask>();
        StatusRemarkCode remark = statusRemarkCodeDAO.findById(OPEN);
        for(ObservationTask task : tasks) {
            task.setStatusRemarks(remark);
            tasksToSave.add(task);
        }
        
        obs.setAssignee(superintedence);
        obs.setDateSubmit(new Date());
        obs.setStatus(remark);
        manager.saveOrUpdate(obs);
        manager.saveOrUpdateTask(tasksToSave);
        User user = getContext().getCurrentUser();

        listOfDraftObservation = manager.getDraftList(observation, user);
        addSimpleMessage("Observation has been submitted.");
        
        if (superintedence != null) {
            LOG.debug("MASUK"+superintedence);
//            String em = emailManager.findEmailByPengguna(superintedence.getEmail());
            Vessel v = vesselDAO.findById(obs.getVessel().getVesselId());
            String crewEmail = v.getCrewExe().getEmail();
            String procEmail = v.getProcExe().getEmail();
            sendNewEditObservationEmail(superintedence.getEmail(), crewEmail, procEmail, superintedence.getUserId(), user.getUserId(), obs);
        }
        
        //Integration with shipVisit3.0 altered by Mansur on 04052014
//        ShipVisit3IntegrateAction sv3 = new ShipVisit3IntegrateAction();
//        sv3.ShipVisit3Observation(obs, user)
        svManager.ShipVisit3Observation(obs, user);

        return new JSP("observation/draft_report.jsp");
    }

    public Resolution updateStatusRemark() {
        String result = "0";
        String idTask = getContext().getRequest().getParameter("id");
        String val = getContext().getRequest().getParameter("val");
        ObservationTask task = manager.getObservationTask(idTask);
        if (task != null) {
            StatusRemarkCode remark = statusRemarkCodeDAO.findById(Integer.valueOf(val));
            task.setStatusRemarksTemp(remark);            
            manager.saveOrUpdateTask(task);
            result = "1";              
        }
        return new StreamingResolution("text/plain", result);
    }

    public Resolution updateComment() {
        String result = "0";
        String idTask = getContext().getRequest().getParameter("id");
        String val = getContext().getRequest().getParameter("val");
        ObservationTask task = manager.getObservationTask(idTask);
        if (task != null) {
//            task.setMaRemarksTemp(StringEscapeUtils.escapeXml(val));
            task.setMaRemarksTemp(val);
//            task.setSummary("");
            manager.saveOrUpdateTask(task);            
            result = "1";
        }
        return new StreamingResolution("text/plain", result);
    }

    public Resolution saveSuperintendenceRemark() {
        ObservationTask task = manager.getObservationTask(String.valueOf(observationTask.getObservationTaskId()));
//        task.setSummaryTemp(StringEscapeUtils.escapeXml(observationTask.getSummaryTemp()));
        task.setSummaryTemp(observationTask.getSummaryTemp());
//        task.setActionPlasFolderTemp(null);
//        task.setMaRemarks("");
        task.setMaRemarksTemp("");
        manager.saveOrUpdateTask(task);
        observation = manager.getObservation(String.valueOf(observation.getObservationId()));

        if (observation != null) {
//            doSaveUpdateModifyTask();
            List<ObservationSummary> listOfSummary = observation.getSummaryList();
            if (listOfSummary != null && listOfSummary.size() > 0) {
                for (int i = 0; i < listOfSummary.size(); i++) {
                    ObservationSummary sum = listOfSummary.get(i);
                    summary[i] = sum.getSummary();
                }
            }
        }
        setTabPosition("2");
        return new JSP("observation/superintendence_form.jsp");
    }

    public Resolution addSeverityDays() {
        ObservationTask task = manager.getObservationTask(String.valueOf(observationTask.getObservationTaskId()));
        task.setSeverityDayAdd(observationTask.getSeverityDayAdd());
        manager.saveOrUpdateTask(task);
        observation = manager.getObservation(String.valueOf(observation.getObservationId()));
//        doSaveUpdateModifyTask();

        return new RedirectResolution(ObservationAction.class, "updateObsRemarkStatus")
                .addParameter("id", observation.getObservationId())
                .addParameter("tabPosition", 2);
    }
    
    public Resolution getSeverityDays() {
        String result = "";
        id = getContext().getRequest().getParameter("id");
        result = manager.getSeverityDay(id);
        return new StreamingResolution("text/plan",result);
    }

    private void doSaveUpdateModifyTask() {
        InfoAudit ia = observation.getInfoAudit();
        User user = getContext().getCurrentUser();
        if (ia == null) {
            ia = new InfoAudit();
            ia.setCreateDate(new Date());
            ia.setCreateId(user);
            ia.setUpdateDate(new Date());
            ia.setUpdateId(user);
        } else {
            ia.setUpdateDate(new Date());
            ia.setUpdateId(user);
        }
        observation.setInfoAudit(ia);
        observation = manager.saveOrUpdate(observation);
    }   
    
    private void sendNewEditObservationEmail(String emailAddress, String crewEmail, String procEmail, String toUser, String fromUser, Observation obs) {
        
        if (StringUtils.isNotBlank(emailAddress)) {
            
            
            String[] combine = {emailAddress,crewEmail,procEmail};
            
            String[] recipient = (String[])ArrayUtils.addAll(conf.getProperty("email.obs.to").split(","), combine);
            
            String[] ccRecipient = (String[])ArrayUtils.addAll(conf.getProperty("email.coo").split(","), manager.getMaEmail(fromUser));
            
            try {
                // freemarker stuff.
                Configuration cfg = new Configuration();
                FileTemplateLoader templateLoader = new FileTemplateLoader(new File(conf.getProperty("email.template.path")));
                cfg.setTemplateLoader(templateLoader);
                cfg.setObjectWrapper(new DefaultObjectWrapper());
                Template template = cfg.getTemplate("html-new-observation.ftl");
                Map<String, Object> rootMap = new HashMap<String, Object>();
                rootMap.put("to", toUser);
                rootMap.put("vessel", obs.getVessel().getVesselName());
                rootMap.put("dateInspection", sdf.format(obs.getDateOfInspection()));
                rootMap.put("tasks", getEmailNewEditTasks(obs).toArray());
                rootMap.put("from", fromUser);
                rootMap.put("totals", totals);
                rootMap.put("totals_day", totalsDay);
                Writer out = new StringWriter();
                template.process(rootMap, out);                
                emailUtil.send(recipient, ccRecipient, "NEW OBSERVATION", out.toString(), "text/html");
                // freemarker stuff ends.
            } catch (Exception ex) {
                LOG.error("error occured {}!! ", ex);
            }
        }
    }
    
    private List<Map<String,String>> getEmailNewEditTasks(Observation obs) {
        List<ObservationTask> tasks = obs.getTaskList();
        List<Map<String,String>> list = new ArrayList<Map<String,String>>();
        Map<String,String> emailTasks = new HashMap<String,String>();
        int high = 0;
        int low = 0;
        int medium = 0;
        int lowDays = 0;
        int mediumDays = 0;
        int highDays = 0;
        
        for(ObservationTask task : tasks) {
           switch(task.getSeverity().getSeverityCodeId()){
               case 1 : {
                   low++;
                   lowDays = lowDays 
                           + (task.getSeverityDayCount()==null?0:task.getSeverityDayCount()) 
                           + (task.getSeverityDayAdd()==null?0:task.getSeverityDayAdd());
                   break;
               }
               case 2: {
                   medium++;
                   mediumDays = mediumDays  + (task.getSeverityDayCount()==null?0:task.getSeverityDayCount()) 
                           + (task.getSeverityDayAdd()==null?0:task.getSeverityDayAdd());
                   break;
               }
               case 3:{
                   high++;
                   highDays = highDays  + (task.getSeverityDayCount()==null?0:task.getSeverityDayCount()) 
                           + (task.getSeverityDayAdd()==null?0:task.getSeverityDayAdd());
                   break;
               } 
           }
        }
        
        emailTasks.put("severity", "LOW");
        emailTasks.put("total", String.valueOf(low));
        emailTasks.put("days", String.valueOf(lowDays));
        list.add(emailTasks);
        emailTasks = new HashMap<String,String>();
        emailTasks.put("severity", "MEDIUM");
        emailTasks.put("total", String.valueOf(medium));
        emailTasks.put("days", String.valueOf(mediumDays));
        list.add(emailTasks);
        emailTasks = new HashMap<String,String>();
        emailTasks.put("severity", "HIGH");
        emailTasks.put("total", String.valueOf(high));
        emailTasks.put("days", String.valueOf(highDays));
        list.add(emailTasks);
        totals = high + medium + low;
        totalsDay = highDays + mediumDays + lowDays;
        return list;
    }
    
    private String getTemplate(List<Map<String, String>> tasks, String toUser, String fromUser ) {
        
        Writer out = new StringWriter();
        
        try {
                // freemarker stuff.
                Configuration cfg = new Configuration();
                FileTemplateLoader templateLoader 
                        = new FileTemplateLoader(new File(conf.getProperty("email.template.path")));
                cfg.setTemplateLoader(templateLoader);
                cfg.setObjectWrapper(new DefaultObjectWrapper());
                Template template = cfg.getTemplate("html-ack.ftl");
                Map<String, Object> rootMap = new HashMap<String, Object>();
                rootMap.put("to", toUser);
                rootMap.put("tasks", tasks.toArray());
                rootMap.put("from", fromUser);

                
                template.process(rootMap, out);
                // freemarker stuff ends.
            } catch (Exception ex) {
                LOG.error("error occured {}!! ", ex);
            }  
        return out.toString();
    }

    public Observation getObservation() {
        return observation;
    }

    public void setObservation(Observation observation) {
        this.observation = observation;
    }

    public String[] getSummary() {
        return summary;
    }

    public void setSummary(String[] summary) {
        this.summary = summary;
    }

    public String[] getSummaryId() {
        return summaryId;
    }

    public void setSummaryId(String[] summaryId) {
        this.summaryId = summaryId;
    }

    public String getTabPosition() {
        return tabPosition;
    }

    public void setTabPosition(String tabPosition) {
        this.tabPosition = tabPosition;
    }

    public List<Observation> getListOfObservation() {
        return listOfObservation;
    }

    public void setListOfObservation(List<Observation> listOfObservation) {
        this.listOfObservation = listOfObservation;
    }

    public List<Observation> getListOfDraftObservation() {
        return listOfDraftObservation;
    }

    public void setListOfDraftObservation(List<Observation> listOfDraftObservation) {
        this.listOfDraftObservation = listOfDraftObservation;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public ObservationTask getObservationTask() {
        return observationTask;
    }

    public void setObservationTask(ObservationTask observationTask) {
        this.observationTask = observationTask;
    }

    public List<FileBean> getDocuments() {
        return documents;
    }

    public void setDocuments(List<FileBean> documents) {
        this.documents = documents;
    }

    public FileBean getDocument() {
        return document;
    }

    public void setDocument(FileBean document) {
        this.document = document;
    }

    public String[] getCb() {
        return cb;
    }

    public void setCb(String[] cb) {
        this.cb = cb;
    }

    public static void main(String[] args) {

        try {
            List<Map<String,String>> tasks =  new ArrayList<Map<String,String>>();
            
            Map<String,String> map = new HashMap<String,String>();
            map.put("severity", "LOW");
            map.put("total", "1");
            map.put("days", "30");
            tasks.add(map);
            map = new HashMap<String,String>();
            map.put("severity", "HIGH");
            map.put("total", "2");
            map.put("days", "20");
            tasks.add(map);
            
            // freemarker stuff.
            Configuration cfg = new Configuration();
            FileTemplateLoader templateLoader = new FileTemplateLoader(new File("/home/fikri/Works/Projects/rnd/freemarker/"));
            cfg.setTemplateLoader(templateLoader);
            cfg.setObjectWrapper(new DefaultObjectWrapper());
            Template template = cfg.getTemplate("html-mail-template.ftl");
            Map<String, Object> rootMap = new HashMap<String, Object>();
            rootMap.put("to", "UNN");
            rootMap.put("vessel", "VESSEL");
            rootMap.put("dateInspection", "06/01/2013");
            rootMap.put("tasks", tasks.toArray());
            rootMap.put("from", "ddd");
            Writer out = new StringWriter();
            template.process(rootMap, out);
            LOG.debug(out.toString());
            // freemarker stuff ends.
        } catch (Exception ex) {
            LOG.error("error occured {}!! ", ex);
        }

    }

    public String getForXlsx() {
        return forXlsx;
    }

    public void setForXlsx(String forXlsx) {
        this.forXlsx = forXlsx;
    }

    public String getForDocx() {
        return forDocx;
    }

    public void setForDocx(String forDocx) {
        this.forDocx = forDocx;
    }

    public String getForPptx() {
        return forPptx;
    }

    public void setForPptx(String forPptx) {
        this.forPptx = forPptx;
    }

    public String getForXls() {
        return forXls;
    }

    public void setForXls(String forXls) {
        this.forXls = forXls;
    }

    public String getForDoc() {
        return forDoc;
    }

    public void setForDoc(String forDoc) {
        this.forDoc = forDoc;
    }

    public String getForPpt() {
        return forPpt;
    }

    public void setForPpt(String forPpt) {
        this.forPpt = forPpt;
    }

    public String getForPdf() {
        return forPdf;
    }

    public void setForPdf(String forPdf) {
        this.forPdf = forPdf;
    }

    public String getForVideoMov() {
        return forVideoMov;
    }

    public void setForVideoMov(String forVideoMov) {
        this.forVideoMov = forVideoMov;
    }

    public String getForVideoMkv() {
        return forVideoMkv;
    }

    public void setForVideoMkv(String forVideoMkv) {
        this.forVideoMkv = forVideoMkv;
    }

    public String getForVideoMp4() {
        return forVideoMp4;
    }

    public void setForVideoMp4(String forVideoMp4) {
        this.forVideoMp4 = forVideoMp4;
    }

    public String getForVideoAvi() {
        return forVideoAvi;
    }

    public void setForVideoAvi(String forVideoAvi) {
        this.forVideoAvi = forVideoAvi;
    }

    public String getForVideoMpeg() {
        return forVideoMpeg;
    }

    public void setForVideoMpeg(String forVideoMpeg) {
        this.forVideoMpeg = forVideoMpeg;
    }

    public String getForVideoWmv() {
        return forVideoWmv;
    }

    public void setForVideoWmv(String forVideoWmv) {
        this.forVideoWmv = forVideoWmv;
    }

    public String getForVideoAsf() {
        return forVideoAsf;
    }

    public void setForVideoAsf(String forVideoAsf) {
        this.forVideoAsf = forVideoAsf;
    }

    public String getForVideoFlv() {
        return forVideoFlv;
    }

    public void setForVideoFlv(String forVideoFlv) {
        this.forVideoFlv = forVideoFlv;
    }

    public String getForVideoRmvb() {
        return forVideoRmvb;
    }

    public void setForVideoRmvb(String forVideoRmvb) {
        this.forVideoRmvb = forVideoRmvb;
    }

    public String getForVideo3gp() {
        return forVideo3gp;
    }

    public void setForVideo3gp(String forVideo3gp) {
        this.forVideo3gp = forVideo3gp;
    }

    public String getYearOfInspection() {
        return yearOfInspection;
    }

    public void setYearOfInspection(String yearOfInspection) {
        this.yearOfInspection = yearOfInspection;
    }

    public ObservationHistoryTask getHistory() {
        return history;
    }

    public void setHistory(ObservationHistoryTask history) {
        this.history = history;
    }

    public String getObsID() {
        return obsID;
    }

    public void setObsID(String obsID) {
        this.obsID = obsID;
    }
    
}
